package heilongjiang;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.junit.Test;

import com.buaa.domain.Institution;
import com.buaa.utils.JacksonUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class test {

	@Test
	public void test1() {
		Map<String, List<Map<Long, List<Object>>>> insLoc = new HashMap<String, List<Map<Long, List<Object>>>>();
		List<Object> list = new ArrayList<Object>();
		list.add("unit_name");
		list.add("unit_addr");
		Map<Long, List<Object>> tablepart = new HashMap<Long, List<Object>>();
		tablepart.put(13061079L, list);
		List<Map<Long, List<Object>>> list2 = new ArrayList<Map<Long, List<Object>>>();
		list2.add(tablepart);
		insLoc.put("lng#lat", list2);

		ObjectMapper objectMapper = new ObjectMapper();
		String str = null;
		try {
			str = objectMapper.writeValueAsString(insLoc);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		System.out.println(str);
	}

	@Test
	public void test2() {
		// ArrayList<Object> list = new ArrayList<Object>();
		// list.add(null);
		// list.add(null);
		// System.out.println(list.size());
		// Object object = 2322;
		// Long num = Long.parseLong(object.toString());
		// System.out.println(num);

		Set<Map<String, Integer>> treeSet = new TreeSet<Map<String, Integer>>(new Comparator<Map<String, Integer>>() {
			@Override
			public int compare(Map<String, Integer> o1, Map<String, Integer> o2) {
				int  i = o1.get("1").compareTo(o2.get("1"));
				
				if (i>0) {
					return 1;
				}
				else if (i<0) {
					return -1;
				}
				else {
					return 0;					
				}
			}
		});
		Map<String, Integer> map;
		map = new HashMap<String, Integer>();
		map.put("1", 31);
		map.put("2", 32);
		treeSet.add(map);
	    map = new HashMap<String, Integer>();
		map.put("1", 21);
		map.put("2", 22);
		treeSet.add(map);
		System.out.println(treeSet);
		System.out.println(JacksonUtil.toJSon(treeSet));

	}
	
	@Test
	public void test3() {
//		List<Object> list = new ArrayList<Object>();
//		list.add(null);
//		list.add(null);
//		System.out.println(JacksonUtil.toJSon(list));
		System.out.println("绥化市".endsWith("市"));
			
		// 对空值进行转换不会报错
		Institution institution = (Institution)null;
	}
}
